﻿//Copyright 2009 - InRAD, LLC
//All Rights Reserved.

using System;
using System.Collections.Generic;
using System.Web.Mvc;

namespace DecisionMaking.WebApp.Charts
{
	/// <summary>
	/// Container for the actual extension method.
	/// </summary>
	public static class FusionChartsHtmlHelper
	{
		/// <summary>
		/// Gets a helper for building a fusion chart.
		/// </summary>
		/// <param name="helper"></param>
		/// <returns></returns>
		public static FusionChartsHelper FusionCharts(this HtmlHelper helper)
		{
			return new FusionChartsHelper(helper);
		}
	}

	/// <summary>
	/// An HTML helper for FusionCharts. 
	/// </summary>
	/// <author>MBH</author>
	/// <dateAuthored>11/09/09</dateAuthored>
	public class FusionChartsHelper
	{
		/// <summary>
		/// The HTML helper.
		/// </summary>
		private readonly HtmlHelper _htmlHelper;

		/// <summary>
		/// The resolved path to the Fusion Charts SWF files.
		/// </summary>
		private readonly string _chartsFolderBase;

		/// <summary>
		/// Initializes the helper. 
		/// </summary>
		/// <param name="helper"></param>
		public FusionChartsHelper(HtmlHelper helper)
		{
			_htmlHelper = helper;
			var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);

			_chartsFolderBase = urlHelper.Content("~/Charts/");
		}

	    /// <summary>
	    /// Gets a fusion chart builder that will create a 2D bar chart.
	    /// </summary>
	    /// <typeparam name="T">The type of the data items.</typeparam>
	    /// <param name="categories"></param>
	    /// <param name="data">The items to bind to the chart.</param>
	    /// <param name="width">Width in pixels.</param>
	    /// <param name="height">Height in pixels.</param>
	    /// <param name="getValue">Delegate that extracts the numerical value from a data item.</param>
	    /// <returns>A 2D chart builder.</returns>
	    public FusionChartsLine2DBuilder<T> Line2D<T>(
            int[] categories,
			IEnumerable<DataSet<T>> data, 
			int width, 
			int height,  
			Func<T, double> getValue)
		{
			return new FusionChartsLine2DBuilder<T>(_htmlHelper, _chartsFolderBase, categories, data, getValue, width, height);
		}

		
	}
}